# include <bits/stdc++.h>
using namespace std;

int n, m, k;
string p;
bool work(int x) { 
    p.clear();
    while(x) { 
        p += (char) ((x & 1) + '0');
        x >>= 1;
    }
    k = 0;
    for(int i = 0; i < (int) p.size(); i++) { 
        k += (int) (p[i] - '0') * pow(10, i);
    }
    return !(k % n);
}

int main() { 
# ifndef LOCAL
    freopen("torch.in", "r", stdin);
    freopen("torch.out", "w", stdout);
# endif
    cin >> n;
    for(m = 1; m <= 256; m++) { 
        if(work(m)) { 
            printf("%d\n", k / n);
            break;
        }
    }
}
